﻿<!DOCTYPE html>
<html>
<head>
<title>Sender</title>
<style>
.video_class{
	width:50%;
	height:50%;
	background: #000;
}
#live_name_information_section{
	position:fixed;
	left:0;
	right:0;
	top:0;
	bottom:0;
	border:2px solid #cccccc;
	z-index = 99;
	background-color: #f5f5f5;
	border-radius: 4px;
}
.input_live_info{
	margin-left:10%;
	width:80%;
	height:10%;
	opacity:0.8;filter(alpha=80);
    display: block;
    padding: 9.5px;
    color: #333333;
    background-color: #dcdcdc;
    border: 1px solid #cccccc;
    border-radius: 4px;
}
.input_live_info:hover{
	opacity:1;filter(alpha=100);
}
#live_info{
	height:20%;
}
.input_help{
	margin-left:10%;
}
.input_help_button{
	margin-left:10%;
	width:80%;
	height:10%;
	opacity:0.8;filter(alpha=80);
    display: block;
    padding: 9.5px;
    color: #333333;
    background-color: #f5f5f5;
    border: 1px solid #cccccc;
    border-radius: 4px;
}
.input_help_button:hover{
	opacity:1;filter(alpha=100);
	background-color:#cccccc;
}
.input_help_button:disabled{
	opacity:0.5;filter(alpha=0.5);
	background-color:#333333;
}
</style>
	<script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript" src="js/jquery.color-2.1.2.min.js"></script>
    <script type="text/javascript" src="js/bootstrap.min.js"></script>
    <script type="text/javascript" src="js/bootstrap.bundle.min.js"></script>
    <script type="text/javascript" src="js/swiper.js"></script>


    <script type="text/javascript" src="myjs/ajaxutils.js"></script>
    <script type="text/javascript" src="myjs/base.js"></script>


    <link rel="stylesheet" href="css/bootstrap.min.css"/>
    <link rel="stylesheet" href="css/bootstrap-reboot.css"/>
    <link rel="stylesheet" href="css/bootstrap-grid.css"/>
    <link rel="stylesheet" href="css/swiper.css">
    <link rel="stylesheet" href="mycss/base.css">
	<link rel="stylesheet" href="mycss/userinfo.css">

    <meta name="viewport" content="width=device-width, initial-scale=1">
	
</head>
<!--<body onbeforeunload="beforeunloadFn()" onunload="unloadFn()">-->
<body>
<nav id="nav_bar" class="navbar navbar-expand-md bg-dark navbar-dark justify-content-center align-items-center">
    <!-- Brand -->
    <div class="d-flex  justify-content-center align-items-center flex-wrap" style="width: 95rem;margin: 0 auto">
        <a class="navbar-brand my-auto" href="#" style="font-size: 1.8rem;font-weight: bold">
            <!--            <img src="https://edu-image.nosdn.127.net/C0124E0336721FF65563B76A16A8143F.png?imageView&thumbnail=190y28&quality=100"-->
            <!--                 alt="Logo">-->
            <span class="glyphicon glyphicon-book" style="color: lawngreen"></span> Elearning
        </a>

        <!-- Toggler/collapsibe Button -->
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar">
            <span class="navbar-toggler-icon"></span>
        </button>

        <!-- Navbar links -->
        <div class="collapse navbar-collapse justify-content-between" id="collapsibleNavbar">
            <ul class="navbar-nav">
                <li class="nav-item">
                    <a href="Home.html" class="nav-link">首页</a>
                </li>
                <li class="nav-item">
                    <a href="CourseList.html" class="nav-link">所有课程</a>
                </li>
                <li class="nav-item">
                    <a href="userinfo.html#/user/courses_info" class="nav-link">我的课程</a>
                </li>
                <li class="nav-item">
                    <a href="LiveList.html" class="nav-link">浏览直播</a>
                </li>
            </ul>

            <div id="search_bar" class="form-inline d-flex justify-content-center sm-hide">
                <form class="form-inline" action="Search.html" method="post" target="_top" name="nav-form"
                      onsubmit="setSearchKey()">
                    <input class="form-control" type="search" placeholder="搜索感兴趣的课程" required name="search-box">
                    <button class="btn btn-success" type="submit"><i class="fa fa-search" aria-hidden="true">搜索</i>
                    </button>
                </form>
                <!--                <input class="form-control " type="text" placeholder="搜索课程"/>-->
                <!--                <button class="btn btn-primary" type="submit">搜索</button>-->
            </div>
            <div id="head_div"
                 class="text-center d-flex justify-content-center align-items-center position-relative sm-hide mx-auto"
                 style="height: 45px;width: 130px;">
                <div id="alarm_ico_div">
                    <a id="alarm_ico" href="Message.html" class="p-1 m-2" style="font-size: 25px;position: relative">
                        <span id="alarm_ico_word" class="glyphicon glyphicon-bell"></span>
                        <span id="alarm_ico_count" style="color: white;text-decoration: none;display: none">0</span>
                    </a>
                </div>
                <img class="user_head_img" id="user_head"
                     style="width: 44px;height: 44px;border: 2px solid #343a40;cursor: pointer" alt="头像">
                <!--用户菜单悬浮框-->
                <div id="user_flex" class="card m-0" style="overflow: hidden;right: 0;top: 100%">
                    <div class="card-body d-flex justify-content-center flex-wrap">
                        <div id="user_head_name" class="d-flex">
                            <img class="user_head_img" alt="头像"/>
                            <div class="ml-4">
                                <h4 class="user_name_all" id="flex_user_name" style="font-size: 1.5rem"></h4>
                                <span style="font-size: 13px;color: #6c757d">手机号:</span><span class="user_phone_all"
                                                                                              id="flex_user_phone"
                                                                                              style="font-size: 13px;color: #6c757d"></span>
                            </div>
                        </div>
                        <div id="user_flex_btn_div" class="p-1 mt-2 d-flex flex-wrap justify-content-around">
                            <a href="userinfo.html#/user/courses_info" class="user_flex_btn">
                                <span class="glyphicon glyphicon-book"></span>
                                <span>&ensp;我的课程</span>
                            </a>
                            <a href="userinfo.html#/user/order_info" class="user_flex_btn">
                                <span class="glyphicon glyphicon-list-alt"></span>
                                <span>&ensp;订单管理</span>
                            </a>
                            <a href="userinfo.html#/user/courses_published" class="user_flex_btn mt-2">
                                <span class="glyphicon glyphicon-upload"></span>
                                <span>&ensp;发布课程</span>
                            </a>
                            <a href="userinfo.html#/user/user_info" class="user_flex_btn mt-2">
                                <span class="glyphicon glyphicon-cog "></span>
                                <span>&ensp;个人设置</span>
                            </a>
                        </div>
                        <button id="open_live_btn" type="button" class="btn btn-primary mx-auto mt-1"
                                style="border-radius: 100px;">开启直播
                        </button>
                        <button onclick="logout()" type="button" class="btn btn-danger mx-auto mt-1"
                                style="border-radius: 100px;">注销登录
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</nav>
<!--主播信息-->
<div id="back_img_div" class="d-flex" style="min-width: 95rem">
    <div id="user_short_info_div" class="d-flex align-items-center">
        <div class="p-2 ml-4">
            <img class="user_head_img" id="user_big_head_img">
        </div>
        <div id="user_short_info" class="ml-3">
            <h1 class="user_name user_name_all" id="show_live_name"></h1>
            <p>
                <!--<span id='show_live_name'>默认直播间标题</span>
                -->
				<span>直播人:<span id='show_live_teacher_name' class="user_phone_all"></span>  当前观看人数<span id='watcher_number' class="user_phone_all">0</span> 人</span>
            </p>
            <p>直播描述:<span id='show_live_info' class="user_description_all">啥也没有</span></p>
			<!--<p>当前观看人数 <span id='watcher_number'>0</span> 人</p>-->
        </div>
    </div>
</div>
	<center>
	<div id='video_play_section'>
		<video id="localVideo" class='video_class' autoplay></video><br>
	</div>
	</center>
		<div id='live_name_information_section'>
			<br><br>
			<center><h2>创建直播</h2></center>
			<p class='input_help'>直播间标题</p>
			<input id="live_name" class='input_live_info' type="text"></input>
			<p class='input_help'>直播间描述(选填)</p>
			<textarea id="live_info" class='input_live_info'  type="text"></textarea>
			</center>
			<center><label id="upload_course_img_btn" for="course_img_edit" class="p-2 my_button my_button_primary">选择图片</label>
            <input type="file" id="course_img_edit" name="file" style="display:none">
			<label id='button_start' disabled='true' class='p-2 my_button my_button_primary'>发起直播</label>
			<center>
			<br>
			<img id='display_cover' width="200" height="200" alt="预览"></img>
			</center>
		<!--
			<input id="choose_live_" class='input_live_info' type="file"></input>
			
			<p class='input_help'>用户id for test</p>
			<input id="liver_id" class='input_live_info'  type="text"></input><br>
			-->
			<!--<button id='button_start' disabled='true' class='input_help_button'>发起直播</button>-->
			
			<!--<button id='test'>slide测试</button>-->
		</div>
	<!--
	<div>
	<textarea id='pilipili'></textarea>
	<input id='fire_pili'>发送</input>
	</div>
	-->
    <script>
		//上传文件后显示预览图片
		var live_cover_file = null;
		$("#course_img_edit").change(function () {
			if (this.files[0] == null)
				return;
			let fileReader = new FileReader();
			fileReader.readAsDataURL(this.files[0]);
			fileReader.onload = function () {
				$("#display_cover").attr("src", fileReader.result);
			};
		});

	
		console.log(window.location.search);
		var str_token = window.location.search;
		var user_token;
		try{
			user_token = str_token.split("?")[1].split("=")[1];
			console.log('token = '+user_token);
		}catch(error){
			console.log('test page');
		}
		
		
		
		$('#test').click(function(){
		
				//数据库检查是否有直播资格，返回允许后才会消失
				$('#live_name_information_section').slideUp();
		});
	/*
		navigator.mediaDevices.enumerateDevices()
		.then(function(devices) {
			console.log('available device:');
			devices.forEach(function(device) {
				console.log(device.kind + ": " + device.label +" id = " + device.deviceId);
			});
		})
		.catch(function(err) {
			console.log(err.name + ": " + err.message);
		});
*/
		var startvideo2 = false;
		var button_start = document.getElementById('button_start');

		var liver_id = null;
		var live_name = null;
		var live_info = null;
		var reader = new FileReader();
		
		
        // 与信令服务器的WebSocket连接
        //var socket = new WebSocket("ws://127.0.0.1:3000");
		var socket = new WebSocket("ws://182.92.1.116:3000");
		
		var mediaOpts = {
			audio: true,
			video: true
			//video: { width: 1280, height: 720 }
			// video: { facingMode: "environment"}, // 或者 "user"
		}
  
        // stun和turn服务器
        /*
		var iceServer = {
            "iceServers": [{
                "url": "stun:stun.l.google.com:19302"
            }, {
                "url": "turn:numb.viagenie.ca",
                "username": "webrtc@live.com",
                "credential": "muazkh"
            }]
        };*/
		var iceServer = { iceServers: [
						{
							urls:"stun:stun.l.google.com:19302"
						},
						{
                        urls: "turn:106.52.27.49:3478",
						username:"winka",
						credential:"9587"
                      }]
		};
		

        // 创建PeerConnection实例 (参数为null则没有iceserver，即使没有stunserver和turnserver，仍可在局域网下通讯)
        var pc = new RTCPeerConnection(iceServer);
		

		var datachannel = pc.createDataChannel('send_Blob');
		datachannel.binaryType = 'arraybuffer';
		datachannel.onerror = function(error){
			console.log('===error occur at datachannel===');
			console.log(error);
		}
		datachannel.onopen = function(event){
			console.log(event);
		}
		datachannel.onclose = function(event){
			console.log(event);
		}
		console.log(pc);
        // 发送ICE候选到其他客户端
        pc.onicecandidate = function(event){
			console.log('on ice ready');
            if (event.candidate !== null) {
				
				//找到ice候选后socket发送
				//if(!pc || !pc.remoteDescription.type){
                socket.send(JSON.stringify({
                    "event": "_ice_candidate",
                    "candidate": event.candidate
                    
                }));
				//}
            }
			console.log('on ice ready end');
        };

		
        // 发送offer和answer的函数，发送本地session描述
        var sendOfferFn = function(desc){
			console.log('send offer');
			console.log(desc);
            pc.setLocalDescription(desc);
            socket.send(JSON.stringify({ 
                "event": "_offer",
				"data":desc
            }));
			console.log('send who I am after send offer');
			socket.send(JSON.stringify({
                   "event": "_who",
					"data": "sender",
					"liver": liver_id,//从input中读取的变量
					"live_name":live_name,
					"live_info":live_info,
					"watcher": liver_id
			}));
        };
		
		

        // 获取本地音频和视频流
		console.log('get camera');
		//检查浏览器支持的编码格式
		var types = ["video/webm", 
             "audio/webm", 
             "video/webm\;codecs=vp8", 
			 "video/webm\;codecs=vp9", 
             "video/webm\;codecs=daala", 
             "video/webm\;codecs=h264", 
             "audio/webm\;codecs=opus", 
			 'video/webm; codecs=what',
			 'video/webm; codecs=opus,vp8',
			 'video/webm; codecs=opus,vp9',
             "video/mpeg"];

	for (var i in types) { 
		console.log( "Type " + types[i] + " is" + (MediaRecorder.isTypeSupported(types[i]) ? " support " : " not support")); 
	}
		
		
		
		
		//Camera调用成功
		function successFunc(stream) {
			//发送给DB检查是否有直播权限
			//sendtoDB_checkpermission(live_name);
			
			// 处理页面元素
			$('#live_name_information_section').slideUp();
			slide_status = false;
			button_start.disabled = true;
			
			var video = document.getElementById('localVideo');
			console.log(stream);
			if ("srcObject" in video) {
				console.log('srcObject');
				video.srcObject = stream;
			} else {
				console.log('src');
				video.src = window.URL && window.URL.createObjectURL(stream) || stream
			}
			

			console.log('check pc\'s track');
			console.log(pc);
			
            //发送一个offer信令
			
			console.log('send offer');
            pc.createOffer(sendOfferFn, function (error) {
				console.log('Failure callback: ' + error);
            });
			
			
			//MediaRecorder参数设置
			var record_options = {
				audioBitsPerSecond:128000,
				videoBitsPerSecond:2500000,
				//mimeType:'video/webm'
				mimeType:'video/webm; codecs=opus,vp8'
			}
			//创建MediaRecorder
			var mediaRecorder = new MediaRecorder(stream,record_options);
			
			console.log(mediaRecorder);
			//每次切分的大小
			const chunkSize = 16384;
			//分片函数
			function readSlice(file,file_offset){
			//文件传输开始前，先发送文件长度信息
				if(file_offset==0){
//					console.log('send file info : '+file.size);
					//datachannel发送文件总长度
					var fileinfo = {
						"filesize":file.size
					}
					datachannel.send(JSON.stringify(fileinfo));
					//接收方只有在收到fileinfo之后才会收集传输到的数据
				}
				
			//切分文件
				var sliceOfFile = file.slice(file_offset,file_offset+chunkSize);
				console.log('slicefile length : '+sliceOfFile.size);
				
				//var arr_temp2 = [];
				//arr_temp2.push(sliceOfFile);
				//var blob_temp2 = new Blob(arr_temp2,{'type':'video/webm; codecs=opus,vp8'});
				//sliceOfFile = blob_temp2;
				
				reader.readAsArrayBuffer(sliceOfFile);
				
				return file_offset+chunkSize;
			}
			//当MediaRecorder数据可用
			mediaRecorder.ondataavailable = function(e) {
				var arr_temp = [];
				arr_temp.push(e.data);
				var blob_temp = new Blob(arr_temp,{'type':'video/webm; codecs=opus,vp8'});
				
				
				//var file_ToSend = e.data;
				var file_ToSend = blob_temp;
				var offset = 0;
				var arraybuffer_toSend;
				console.log(mediaRecorder);
				console.log(file_ToSend);
				
				reader.onloadend = function(event){
//						console.log(reader.result);
						datachannel.send(reader.result);
						//检查是否发送完成
						if(offset<file_ToSend.size){
							offset = readSlice(file_ToSend,offset);
						}
					}
				//当数据可用时，将blob执行readSlice函数，切分成片并且send
				offset = readSlice(file_ToSend,offset);
			}
			//启动录制，每1秒创建一个视频块
			
			mediaRecorder.start();
			setTimeout(stopRecord,1000);
			
			function stopRecord(){
				mediaRecorder.stop();
				mediaRecorder.start();
				setTimeout(stopRecord,1000);
			}

		}
		//调用Camera失败
		function errorFunc(err) {
			switch(err.name){
				case "NotReadableError":
					alert('摄像头被占用:请关闭占用摄像头的进程后重试');
					break;
				case "NotAllowedError":
					alert('没有权限，请允许本页面使用摄像头和麦克风');
					break;
				default:
					alert("Fail to get camera "+err.name);
					break;
			}
			console.log(err);
		}
		function readCamera(){
			//用于兼容
			if (navigator.mediaDevices === undefined) {
				navigator.mediaDevices = {};
			}
			if (navigator.mediaDevices.getUserMedia === undefined) {
				console.log('navigator.mediaDevices.getUserMedia undefined');
				navigator.mediaDevices.getUserMedia = function(constraints) {
					var getUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
					if (!getUserMedia) {
						return Promise.reject(new Error('getUserMedia is not implemented in this browser'));
					}
					return new Promise(function(resolve, reject) {
						getUserMedia.call(navigator, constraints, resolve, reject);
					});
				}
			}
			navigator.mediaDevices.getUserMedia(mediaOpts).then(successFunc).catch(errorFunc);
		}

		
		
        //处理到来的信令
        socket.onmessage = function(event){
            var json = JSON.parse(event.data);
  //          console.log('onmessage: ', json);
            //如果是一个ICE的候选，则将其加入到PeerConnection中，否则设定对方的session描述为传递过来的描述
            if( json.event === "_ice_candidate" ){
				//if(!pc || !pc.remoteDescription.type){
					//push candidate onto queue...
					pc.addIceCandidate(new RTCIceCandidate(json.candidate));
				//}
				
				console.log('add ice');
					//pc.addIceCandidate(new RTCIceCandidate(json.data.candidate));

			}else if(json.event === "_watcher_number"){
				//console.log('watcher_number : '+json.watcher_number);
				$('#watcher_number').text(json.watcher_number);
			
			} else if(json.event === "_answer"){
				console.log('get answer and set RemoteDescription');
                pc.setRemoteDescription(new RTCSessionDescription(json.data));
				console.log(pc);
				start_heartcheck(socket);//启动心跳
                
            }else{
				console.log('else event'+json.event);
			}
			//console.log('handle msg end');
        };
		
		function upload_cover_success(){
			console.log("success upload cover");
			console.log('=========start camera===============');
			readCamera();
		}
		function upload_cover_error(){
			console.log("error upload cover");
		}
		function uploadFile_livecover(url, file, fileName, limitSize, options, success, error, token,liveid_param) {
			liver_id = liveid_param;
			//alert("liveid_uploadFile_livecover:"+liver_id);
			let ajaxBody;
			try{
				console.log("未选择任何文件!")
				if (file.size > limitSize) {
					console.log("文件大小超过限制!")
					return false;
				}
				let formData = new FormData();
					console.log(file);
					formData.append(fileName, file);
					formData.append('token', token);
				for (let option in options) {
					formData.append(option, options[option]);
				}
				ajaxBody = {
					url: url,
					type: 'POST',
					cache: false,
					data: formData,
					processData: false,
					contentType: false,
					success: success,
					error: error
				};
			}catch(e){
				console.log('not select cover');
				readCamera();
			}
			
			
			$.ajax(ajaxBody);
			return true;
		}
		//将直播标题、直播描述、token发送给数据库
		function sendtoDB_checkpermission(live_name_tocheck){
			//alert('sendtoDB_checkpermission');
			var request_list = {
				"liveName":live_name_tocheck,
				"token": user_token
			};
			let data_tosend = JSON.stringify(request_list);
			data_tosend = data_tosend.replace('"token":','"token": ');
			$.ajax({
				type : "POST",
				contentType: "application/json;charset=UTF-8",
				url : "http://120.55.165.31:8080/Elearning/api/teacher/live/addLive",
				data : data_tosend,
				success : function(result) {
					//从result中取得liveId，作为直播发起者的标识发送给服务器
					console.log(result);
					switch(result.status){
						case 401:
							console.log(result.message);
							break;
						case 200:
							console.log('Permission Access');
							console.log(result.data);
							console.log(result.data.liveId);
							liver_id = result.data.liveId;
							//设置直播者信息
							getUserInfoByLiveId(liver_id);
							//上传直播封面
							var option ={
								"liveId":liver_id
							};
							live_cover_file = $('#course_img_edit')[0].files[0];
							//alert('liveId_sendtoDB_checkpermission:'+liver_id);
							uploadFile_livecover('http://120.55.165.31:8080/Elearning/api/liveServer/live/uploadLiveImage',live_cover_file,"liveImageFile",9999999,option,upload_cover_success,upload_cover_error,user_token,liver_id);
							break;
						default:
							localVideo.src = null;//关闭本地摄像头
							alert('Permission status not known:'+result.status);
							break;
					}
				},
            //请求失败，包含具体的错误信息
				error : function(e){
					console.log(e.status);
					console.log(e.responseText);
				}
			});
		}
		
		function startlive(){
			//liver_id = document.getElementById('liver_id').value;
			live_name = document.getElementById('live_name').value;
			$('#show_live_name').text(live_name);
			live_info = document.getElementById('live_info').value;
			$('#show_live_info').text(live_info);
			
			//readCamera();
			sendtoDB_checkpermission(live_name);
			
			//navigator.mediaDevices.getUserMedia(mediaOpts).then(successFunc).catch(errorFunc);
			
			//alert(liver_id);
			//readCamera();
			//navigator.mediaDevices.getUserMedia(mediaOpts).then(successFunc).catch(errorFunc);
		}
		
		button_start.addEventListener('click',startlive,false);
		
		
		//测试用
		//readCamera();
		
		socket.addEventListener('open', function () {
			button_start.disabled = false;
		});
		
		/*
		//页面关闭事件
		function beforeunloadFn(){
			alert('beforeunloadFn');
			socket.send(JSON.stringify({
                   "event": "_page_close",
					"data": "beforeunload"
			}));
		}
		
		function unloadFn(){
			alert('unloadFn');
			socket.send(JSON.stringify({
                   "event": "_page_close",
					"data": "unload"
			}));
		}
		*/
		function handle_websocket_close(event){
			console.log('ws close');
			alert('连接中断');
			var video = document.getElementById('localVideo');
			video.srcObject = null;
			console.log(video);
		}
		//监听websocket断开事件
		socket.addEventListener('close',handle_websocket_close);
		
		
		//循环显示当前ws状态
		function now_ws_state(){
			console.log('now ws state: ' + socket.readyState);
			setTimeout(now_ws_state,1000);
		}
		//setTimeout(now_ws_state,1000);
		
		console.log(socket);
		
		function now_ice_state(){
			console.log('now ice state: ' + pc.iceConnectionState);
			console.log('now ice gathering state: ' + pc.iceGatheringState);
			console.log(pc);
			setTimeout(now_ice_state,1000);
		}

		
		const heartbeat_time = 10000;
		//发送心跳的websocket与每隔多久发送一次
		function start_heartcheck(ws){
			setTimeout(send_heartcheck,heartbeat_time);
		}
		//发送
		function send_heartcheck(ws){
			console.log('heartbeat');
			socket.send(JSON.stringify({
				"event": "_heartcheck",
				"data": "pong"
			}));
			setTimeout(send_heartcheck,heartbeat_time);
		}
		
		//用于显示
		function getUserInfoByLiveId(liveid_param){
			var request_list = {
				"liveId":parseInt(liveid_param)
			};		
			let data_tosend = JSON.stringify(request_list);
			data_tosend = data_tosend.replace('"token":','"token": ');
			$.ajax({
				type : "POST",
				contentType: "application/json;charset=UTF-8",
				url : "http://120.55.165.31:8080/Elearning/api/liveServer/live/selectLiveByLiveId",
				data : data_tosend,
				success : function(result) {
					//从result中取得liveId，作为直播发起者的标识发送给服务器
					console.log(result);
					switch(result.status){
						case 200:
							alert('已经获得直播信息');
							console.log('已经获得直播信息');
							console.log(result.data);
							
							$('#show_live_teacher_name').text(result.data.teacherName);
							//要获得讲师头像，需要用userId去获得头像
							GetAndSetUserImageByUserId(result.data.userId);
							break;
						default:
							alert('无法获得直播信息:'+result.status);
							break;
					}
				},
            	//请求失败，包含具体的错误信息
				error : function(e){
					console.log(e.status);
					console.log(e.responseText);
				}
			});
		}
		
		function GetAndSetUserImageByUserId(userId_param){
			var request_list = {
				"userId":userId_param
			};		
			let data_tosend = JSON.stringify(request_list);
			data_tosend = data_tosend.replace('"token":','"token": ');
			$.ajax({
				type : "POST",
				contentType: "application/json;charset=UTF-8",
				url : "http://120.55.165.31:8080/Elearning/api/all/user/selectUserByUserId",
				data : data_tosend,
				success : function(result) {
					//从result中取得liveId，作为直播发起者的标识发送给服务器
					console.log(result);
					switch(result.status){
						case 200:
							console.log('get userImage');
							$('#user_big_head_img').attr("src","http://120.55.165.31:8080/Elearning/" + result.data.userImage);
							break;
						default:
							alert('无法获得直播信息:'+result.status);
							break;
					}
				},
            	//请求失败，包含具体的错误信息
				error : function(e){
					console.log(e.status);
					console.log(e.responseText);
				}
			});
		
		}
    </script>
</body>
</html>


























